<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8" >
    <title>后台管理-登陆</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/webjars/layui/2.5.7/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/back/back-login.css}">
    <script th:src="@{/webjars/jquery/3.6.0/jquery.min.js}"></script>
    <script th:src="@{/webjars/layui/2.5.7/layui.js}" charset="utf-8"></script>
    <script th:src="@{/js/jq-module/jquery.particleground.min.js}" charset="utf-8"></script>
</head>
<body>
<div class="layui-container">
    <div class="admin-login-background">
        <div class="layui-form login-form">
            <form class="layui-form" action="">
                <div class="layui-form-item logo-title">
                    <h1>驾考系统后台管理登录</h1>
                </div>
                <div class="layui-form-item">
                    <label class="layui-icon layui-icon-username"></label>
                    <input type="text" name="userAccount" lay-verify="required|account" placeholder="用户名或者邮箱" autocomplete="off" class="layui-input" >
                </div>
                <div class="layui-form-item">
                    <label class="layui-icon layui-icon-password"></label>
                    <input type="password" name="password" lay-verify="required|password" placeholder="密码" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn layui-btn-normal layui-btn-fluid" lay-submit="" lay-filter="login">登 录</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    layui.use(['form'], function () {
        let form = layui.form,
            $ = layui.$;
        if (top.location != self.location) top.location = self.location;

        // 粒子线条背景
        $('.layui-container').particleground({
            dotColor:'rgba(149,253,126,0.73)',
            lineColor:'rgba(160,253,126,0.67)'
        });

        // 进行登录操作
        form.on('submit(login)', function (data) {
            // layer.msg(JSON.stringify(data.field));
            $.ajax({
                url: '/user/login',
                method: 'post',
                data: data.field,
                dataType: 'JSON',
                success: function (res){
                    //正确
                    if (res === 0){
                        //登录成功
                        layer.msg('登录成功',{
                            time: 500, // 0.5秒钟跳转到首页
                        },function (){
                            //跳转到首页
                            window.location = '/page/backIndex';
                        })
                    }
                    //密码错误
                    if (res === 1){
                        //密码错误
                        layer.msg("密码错误",{
                            time: 3000 , //如果3s后 没有操作，自动关闭
                            btn: ["我知道了"],
                            btnAlign: 'c',
                            shade: 0.5,
                            anim: 6,
                            yes: function (index, layero){
                                //关闭弹框
                                layer.close(index);
                            }
                        })
                    }
                    //用户名不存在
                    if (res === 2){
                        //密码错误
                        layer.msg("用户名不存在",{
                            time: 20000 , //如果20s后 没有操作，自动关闭
                            btn: ["我知道了"],
                            btnAlign: 'c',
                            shade: 0.5,
                            anim: 6,
                            yes: function (index, layero){
                                //关闭弹框
                                layer.close(index);
                            }
                        })
                    }

                    //用户名不存在
                    if (res === 3){
                        //密码错误
                        layer.msg("对不起，当前账户无权限登录",{
                            time: 20000 , //如果20s后 没有操作，自动关闭
                            btn: ["我知道了"],
                            btnAlign: 'c',
                            shade: 0.5,
                            anim: 6,
                            yes: function (index, layero){
                                //关闭弹框
                                layer.close(index);
                            }
                        })
                    }
                }
            })
            return false;
        });


    });
</script>
</body>
</html>